Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports System.Data.SqlTypes 

Namespace CEL.Modules.CELLibrary
    Partial Class Borrow
        Inherits Entities.Modules.PortalModuleBase

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            cmdActualReturnDate.NavigateUrl = Common.Utilities.Calendar.InvokePopupCal(txtActualReturnDate)
            cmdBorrowDate.NavigateUrl = Common.Utilities.Calendar.InvokePopupCal(txtBorrowDate)
            cmdDueReturnDate.NavigateUrl = Common.Utilities.Calendar.InvokePopupCal(txtDueReturnDate)
            If IsPostBack = True Then Exit Sub
            Call loadUser()
            Call LocalizeSetting()

        End Sub
        Public Sub LocalizeSetting()
            Me.lblActualReturnDate.Text = DotNetNuke.Services.Localization.Localization.GetString("lblActualReturnDate", Me.LocalResourceFile)
            Me.lblBorrowDate.Text = DotNetNuke.Services.Localization.Localization.GetString("lblBorrowDate", Me.LocalResourceFile)
            Me.lblBorrowedBy.Text = DotNetNuke.Services.Localization.Localization.GetString("lblBorrowedBy", Me.LocalResourceFile)
            Me.lblDueReturnDate.Text = DotNetNuke.Services.Localization.Localization.GetString("lblDueReturnDate", Me.LocalResourceFile)
            Me.lnkBack.Text = DotNetNuke.Services.Localization.Localization.GetString("lnkBack", Me.LocalResourceFile)
        End Sub
        Public Sub loadUser()
            Dim objUserCon As New UserController
            Dim objUserInfo As UserInfo
            Dim arrUsers As ArrayList = UserController.GetUsers(PortalId)
            Me.cboBorrrowedBy.Items.Add(New ListItem("<Select User>", 0))
            For Each objUserInfo In arrUsers
                Me.cboBorrrowedBy.Items.Add(New ListItem(objUserInfo.Username, objUserInfo.UserID))
            Next
        End Sub
        Protected Sub lnkBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBack.Click
            Response.Redirect(EditUrl("ManageBooks"), True)
        End Sub

 Protected Sub lnkSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSave.Click
            If Request.QueryString("LibraryID") <> "" Then
		Dim sqldate As SqlDateTime
                Dim objLibraryCon As New CELLibraryController
                If (Me.txtActualReturnDate.Text = "") Then
                    sqldate = SqlDateTime.Null
                Else
                    sqldate = Me.txtActualReturnDate.Text
                End If
                If Me.cboBorrrowedBy.SelectedItem.Value = "0" Then Me.lblError.Text = "Please select user!" : Exit Sub
                If Me.txtBorrowDate.Text = "" Then Me.lblError.Text = "Please select borrow date!" : Exit Sub
                If Me.txtDueReturnDate.Text = "" Then Me.lblError.Text = "Please select due return date!" : Exit Sub
                If Me.cboBorrrowedBy.SelectedItem.Value <> "0" Then objLibraryCon.AddLibraryBorrow(Val(Request.QueryString("LibraryID")), Me.cboBorrrowedBy.SelectedItem.Value, Me.txtBorrowDate.Text, Me.txtDueReturnDate.Text, sqldate)
                Response.Redirect(EditUrl("ManageBooks"), True)
            End If
        End Sub

    End Class
End Namespace
